package kmi.droid.livewallpaper.gl;

import java.io.Writer;

import android.util.Log;

public class LogWriter extends Writer
{
	private StringBuilder _builder = new StringBuilder();

	@Override
	public void close()
	{
		flushBuilder();
	}

	@Override
	public void flush()
	{
		flushBuilder();
	}

	@Override
	public void write(char[] buf, int offset, int count)
	{
		for (int i = 0; i < count; i++)
		{
			char c = buf[offset + i];
			if (c == '\n')
			{
				flushBuilder();
			} else
			{
				_builder.append(c);
			}
		}
	}

	private void flushBuilder()
	{
		if (_builder.length() > 0)
		{
			Log.v("GLSurfaceView", _builder.toString());
			_builder.delete(0, _builder.length());
		}
	}
}
